package com.qiantu.phone.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.qiantu.api.entity.RoomBean;
import com.qiantu.api.entity.SceneAutoCreateInfo;
import com.qiantu.phone.R;
import com.qiantu.phone.app.AppAdapter;

import java.util.List;
import java.util.Map;

public class SceneAutoCreateRoomAdapter extends AppAdapter<Map> {

    public SceneAutoCreateRoomAdapter(Context context) {
        super(context);
    }


    @NonNull
    @Override
    public SceneAutoCreateRoomAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new SceneAutoCreateRoomAdapter.ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {

        private final TextView tvFloorName;
        private final RecyclerView roomRecyclerView;
        private final SceneAutoCreateAdapter createAdapter;

        private ViewHolder() {
            super(R.layout.room_floor_select_item);
            tvFloorName = findViewById(R.id.tv_floor_name);
            roomRecyclerView = findViewById(R.id.room_recycler_view);
            roomRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
            createAdapter = new SceneAutoCreateAdapter(getContext());
            roomRecyclerView.setAdapter(createAdapter);
        }

        @Override
        public void onBindView(int position) {
            Map room = getItem(position);
            //默认楼层不显示
            tvFloorName.setText(room.get("name").toString());
            List<SceneAutoCreateInfo> infoList = (List<SceneAutoCreateInfo>) room.get("data");
            createAdapter.setData(infoList);
        }
    }

}
